import Result from "@/model/Result";
import axios from "@/axios/api";
import type Device from "@/model/Device";
import type PageQuery from "@/model/PageQuery";
import type Page from "@/model/Page";

export default class DeviceApi {

    static get = async (id: number) => {
        return await axios.get<Result<Device>>(`/api/v1/device/${id}`)
            .then(resp => resp.data)
    }

    static remove = async (id: number) => {
        return await axios.delete<Result<Device>>(`/api/v1/device/${id}`)
            .then(resp => resp.data)
    }

    static update = async (id: number, bean: Device) => {
        return await axios.put<Result<void>>(`/api/v1/device/${id}`, bean)
            .then(resp => resp.data)
    }

    static save = async (bean: Device) => {
        return await axios.post<Result<void>>(`/api/v1/device`, bean)
            .then(resp => resp.data)
    }

    static page = async (query: PageQuery) => {
        return await axios.post<Result<Page<Device>>>(`/api/v1/device/page`, query)
            .then(resp => resp.data)
    }

    static getVideo = async (id: number) => {
        return await axios.get<Result<string>>(`/api/v1/device/cameras?id=${id}`)
            .then(resp => {
                return resp.data
            })
    }

    static capture = async (id: number) => {
        return await axios.get<Result<string>>(`/api/v1/device/capture?id=${id}`)
            .then(resp => {
                return resp.data
            })
    }
    static video = async (id: number, time: number) => {
        return await axios.get<Result<string>>(`/api/v1/device/video?id=${id}&time=${time}`)
            .then(resp => {
                return resp.data
            })
    }
}